import Expression from "./interface/Expression";
import MetaData from "./MetaData";
import UnchangedExpression from "./impl/UnchangedExpression";
import ExtendExpression from "./abstract/ExtendExpression";

/** 排序表达式 */
class OrderByExpression extends ExtendExpression {
    protected data: Expression;

    constructor(metadata: MetaData, value: string | Expression) {
        super(metadata);
        this.data = typeof value === 'string' ? new UnchangedExpression(value) : value;
    }

    public orderBy(field: string, sort: "DESC" | "ASC" = 'DESC') {
        return new OrderByExpression(this.metadata, new UnchangedExpression(`,${field} ${sort}`))
    }

    toLocaSql(): string {
        return this.data.toLocaSql();
    }

}

export = OrderByExpression
